package com.egd.imapp.contoller.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.egd.imapp.R;
import com.egd.imapp.contoller.activity.me.AboutMeSetActivity;
import com.egd.imapp.model.Model;
import com.egd.imapp.model.bean.UserInfo;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMUserInfo;
import com.hyphenate.easeui.ui.base.EaseBaseFragment;

public class AboutMeFragment extends EaseBaseFragment implements View.OnClickListener{
    static private String TAG = "TAG";
    private ConstraintLayout clUser;
    private ImageView avatar;
    private TextView nickName_view;
    private TextView userId_view;

    private LinearLayout item_common_set;
    private LinearLayout item_feedback;
    private LinearLayout item_about_imapp;
    private LinearLayout item_developer_set;

    private UserInfo userInfo;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_about_me, container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
        initListener();
    }

    private void initView(Bundle savedInstanceState) {
        avatar = findViewById(R.id.avatar_about_me);
        nickName_view = findViewById(R.id.tv_nickName_about_me);
        userId_view = findViewById(R.id.tv_userId_about_me);

        item_common_set = findViewById(R.id.item_common_set);
        item_feedback = findViewById(R.id.item_feedback);
        item_about_imapp = findViewById(R.id.item_about_imapp);
        item_developer_set = findViewById(R.id.item_developer_set);
        
    }

    private void initListener() {
        item_common_set.setOnClickListener(this);
        item_feedback.setOnClickListener(this);
        item_about_imapp.setOnClickListener(this);
        item_developer_set.setOnClickListener(this);
    }

    private void initData() {
        //获取到当前登录用户的信息
        String hxId = EMClient.getInstance().getCurrentUser();
        Log.e(TAG, "initData: AboutMeFragment  hxId = " + hxId);
        userInfo = Model.getInstance().getUserAccountDao().getAccountByHxId(hxId);

        if (userInfo == null){
            Toast.makeText(mContext, "服务异常，获取数据失败...", Toast.LENGTH_SHORT).show();
            nickName_view.setText("账 号："+ "获取数据失败");
            userId_view.setText("昵称ID: "+"获取数据失败");
        }else {
            nickName_view.setText("账 号："+ userInfo.getHxid());
            userId_view.setText("昵称ID: "+userInfo.getNick());
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.item_common_set:
                startActivity(new Intent(mContext, AboutMeSetActivity.class));
                break;
            case R.id.item_feedback:
                Toast.makeText(mContext, "服务完善中...",Toast.LENGTH_SHORT).show();
                break;
            case R.id.item_about_imapp:
               Toast.makeText(mContext, " 服务完善中...", Toast.LENGTH_SHORT).show();
                break;
            case R.id.item_developer_set:
                Toast.makeText(mContext, " 服务完善中...", Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }
    }
}